/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cassys.interceptors;


import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.Interceptor;
import java.util.Map;

/**
 *
 * @author olivier
 */
public class loginInterceptor implements Interceptor {

    public String intercept(ActionInvocation invocation) throws Exception {
        System.out.println("test");
        Map session = invocation.getInvocationContext().getSession();

        // Is there a "user" object stored in the user's HttpSession?
        Object user = session.get("user");
        if (user == null) {
            return Action.LOGIN;
        } else {
            return invocation.invoke();
        }
    }

    @Override
    public void destroy() {
    }

    @Override
    public void init() {
    }
}
